package cn.com.winning.ecare.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
import cn.com.winning.ecare.common.MyApplication;
import cn.com.winning.ecare.utils.DisplayUtil;

/**
 * 挂号排班主tab
 * @author Administrator
 *
 */
public class GhFour extends TabActivity
{
	private GhFour oThis = this;
	TabHost tabHost;
	private TabWidget mTabWidget;
	private String strysgh;
	private String stryssx;
	private String strys;
	private String strystc;
	private String strysdj;
	private String strKsId;
	private Intent mIntent;
	private ImageButton imb;
	private TextView tv, ys_name, tv_ys;
	private Button ys_dj;
	private ImageView menu_img;
	private ImageButton mainselected;
	private ImageView img;
	MyApplication myApplication;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.gh_four);
		myApplication = (MyApplication) getApplication();
		myApplication.addActivity(this);
		// 获取控件
		findView();
		iniTabHost();
		setOnClick();
	}

	private void setOnClick()
	{
		menu_img.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View view)
			{
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(GhFour.this, GhSeven.class);
				startActivity(intent);
			}
		});
		mainselected.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View view)
			{
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(oThis, Mainmean.class);
				startActivity(intent);
				oThis.finish();
			}
		});
	}

	private void findView()
	{
		imb = (ImageButton) findViewById(R.id.backmenuButton);
		tv = (TextView) findViewById(R.id.ysname);
		ys_name = (TextView) findViewById(R.id.ys_name);
		ys_dj = (Button) findViewById(R.id.ys_dj);
		tv_ys = (TextView) findViewById(R.id.gh_ys);
		img = (ImageView) this.findViewById(R.id.ys_img);
		mIntent = getIntent();
		if (mIntent != null)
		{
			strysgh = mIntent.getStringExtra("strysgh");
			stryssx = mIntent.getStringExtra("stryssx");
			strys = mIntent.getStringExtra("strys");
			strysdj = mIntent.getStringExtra("strysdj");
			strystc = mIntent.getStringExtra("strystc");
			strKsId = mIntent.getStringExtra("strksid");
			if (mIntent.getParcelableExtra("BITMAP") != null)
			{
				Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("BITMAP");
				img.setImageBitmap(bitmap);
			}
		}
		tv.setText(strys);
		ys_name.setText(strys);
		ys_dj.setText("  " + strysdj + "  ");
		tv_ys.setText(strystc);
		imb.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				finish();

			}
		});

		tabHost = getTabHost();
		mTabWidget = (TabWidget) this.findViewById(android.R.id.tabs);
		menu_img = (ImageView) this.findViewById(R.id.menu_yy_img);
		mainselected = (ImageButton) this.findViewById(R.id.mainselected);
	}

	private void iniTabHost()
	{

		Intent intent1 = new Intent();
		intent1.putExtra("strysgh", strysgh);
		intent1.putExtra("strksid", strKsId);
		intent1.setClass(this, GhFrive.class);

		Intent intent2 = new Intent();
		intent2.putExtra("stryssx", stryssx);
		intent2.setClass(this, Doctorcontent.class);

		// 新建一个tab并设置它的，Tag,标题，图标，内容
		tabHost.addTab(tabHost.newTabSpec("排班信息").setIndicator("排班信息").setContent(intent1));
		tabHost.addTab(tabHost.newTabSpec("医生简介").setIndicator("医生简介").setContent(intent2));
		tabHost.setCurrentTab(0);// 设置初始选中状态为第一个tab
		// 初始化TabHost
		for (int i = 0; i < mTabWidget.getChildCount(); i++)
		{
			RelativeLayout view = (RelativeLayout) mTabWidget.getChildAt(i);

			TextView text = (TextView) view.findViewById(android.R.id.title);
			text.setTextSize(18);
			RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) text.getLayoutParams();
			params.width = RelativeLayout.LayoutParams.MATCH_PARENT;
			params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
			text.setLayoutParams(params);
			text.setGravity(Gravity.CENTER);
			view.setBackgroundColor(getResources().getColor(R.color.color_white));
			if (tabHost.getCurrentTab() == i)
			{
				text.setTextColor(getResources().getColor(R.color.listheadtext_color));

			}
			else
			{
				text.setTextColor(getResources().getColor(R.color.test_color_register));
			}
			int heightPx = DisplayUtil.dip2px(this, 50);
			mTabWidget.getChildAt(i).getLayoutParams().height = heightPx;
		}
		// TabHost切换
		tabHost.setOnTabChangedListener(new OnTabChangeListener()
		{

			public void onTabChanged(String tabId)
			{
				// TODO Auto-generated method stub
				for (int i = 0; i < mTabWidget.getChildCount(); i++)
				{
					View view = mTabWidget.getChildAt(i);
					TextView text = (TextView) view.findViewById(android.R.id.title);
					if (tabHost.getCurrentTab() == i)
					{
						text.setTextColor(getResources().getColor(R.color.listheadtext_color));
					}
					else
					{
						text.setTextColor(getResources().getColor(R.color.test_color_register));
					}
				}
			}

		});
	}

}
